<?php

class Admin_NewsController extends Zend_Controller_Action
{

    public function init()
    {
        $option = array(
                'layout'=>'layout',
                'layoutPath'=>APPLICATION_PATH .'/layouts/scripts/admin'
        );
        Zend_Layout::startMvc($option);
        $this->model_news = new Application_Model_News();
    }

    public function indexAction()
    {
       $this->view->headTitle('Danh sách tin');
    }

    public function listAction()
    {
        try {
            $keyword = $this->_request->getParam('keyword');
            if($keyword){
                $select = $this->model_news->select()->where("news_title like '%$keyword%'");
            }
            else
                $select = $this->model_news->Get_All_News();
            $adapter = new Zend_Paginator_Adapter_DbSelect($select);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(10);
            $current = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($current);
            $this->view->news = $paginator;
            
            $this->_helper->layout()->disableLayout();
        }
        catch (Zend_Exception $ex){
            echo $ex;
        }
    }


}



